2020-2021 Sunseeker Telemetry and Lighting System
usci_a_uart_ex3_autoBaudrateDetectionTX.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #include "driverlib.h"
33 
34 //******************************************************************************
61 //******************************************************************************
62 #define BAUD_RATE 9600
63 #define TRANSMIT_DATA_COUNT 0x03
64 #define USCI_A_UART_MULTIPROCESSOR_MODE_ADDRESS 0xAA
65 
66 uint8_t receivedData = 0x00, transmitData = 0x00;
68 
69 void main (void)
70 {
71  //Stop WDT
72  WDT_A_hold(WDT_A_BASE);
73 
74  //P3.4,5 = USCI_A0 TXD/RXD
75  GPIO_setAsPeripheralModuleFunctionInputPin(
76  GPIO_PORT_P3,
77  GPIO_PIN4 + GPIO_PIN5
78  );
79 
80  //Initialize USCI UART module
81  //Baudrate = 9600, clock freq = 1.048MHz
82  //UCBRx = 6, UCBRFx = 13, UCBRSx = 0, UCOS16 = 1
83  USCI_A_UART_initParam param = {0};
84  param.selectClockSource = USCI_A_UART_CLOCKSOURCE_SMCLK;
85  param.clockPrescalar = 6;
86  param.firstModReg = 13;
87  param.secondModReg = 0;
88  param.parity = USCI_A_UART_NO_PARITY;
89  param.msborLsbFirst = USCI_A_UART_LSB_FIRST;
90  param.numberofStopBits = USCI_A_UART_ONE_STOP_BIT;
91  param.uartMode = USCI_A_UART_AUTOMATIC_BAUDRATE_DETECTION_MODE;
92  param.overSampling = USCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION;
93  if (STATUS_FAIL == USCI_A_UART_init(USCI_A0_BASE, &param)){
94  return;
95  }
96 
97  //Enable UART module for operation
98  USCI_A_UART_enable(USCI_A0_BASE);
99 
100  //Transmit Break
101  USCI_A_UART_transmitBreak(USCI_A0_BASE);
102 
103  //Wait till ,odule is ready to transmit again
104  while (!USCI_A_UART_getInterruptStatus(USCI_A0_BASE,
105  USCI_A_UART_TRANSMIT_INTERRUPT_FLAG)) ;
106 
107  //Transmit data
108  USCI_A_UART_transmitData(USCI_A0_BASE,
109  transmitData++);
111 
112  //Enable Receive Interrupt
113  USCI_A_UART_clearInterrupt(USCI_A0_BASE,
114  USCI_A_UART_RECEIVE_INTERRUPT);
115  USCI_A_UART_enableInterrupt(USCI_A0_BASE,
116  USCI_A_UART_RECEIVE_INTERRUPT);
117 
118  //Enter LPM3, interrupts enabled
119  __bis_SR_register(LPM3_bits + GIE);
120  __no_operation();
121 }
122 
123 //******************************************************************************
124 //
125 //This is the USCI_A0 interrupt vector service routine.
126 //
127 //******************************************************************************
128 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
129 #pragma vector=USCI_A0_VECTOR
130 __interrupt
131 #elif defined(__GNUC__)
132 __attribute__((interrupt(USCI_A0_VECTOR)))
133 #endif
134 void USCI_A0_ISR (void)
135 {
136  switch (__even_in_range(UCA0IV,4)){
137  //Vector 2 - RXIFG
138  case 2:
139 
140  //USCI_A0 TX buffer ready?
141  while (!USCI_A_UART_getInterruptStatus(USCI_A0_BASE,
142  USCI_A_UART_TRANSMIT_INTERRUPT_FLAG)) ;
143 
144  //Receive the data
145  receivedData = USCI_A_UART_receiveData(USCI_A0_BASE);
146 
147  if (transmitDataCount){
148  //Send data
149  USCI_A_UART_transmitData(USCI_A0_BASE,
150  transmitData++);
152  } else {
153  //Send Break
154  USCI_A_UART_transmitBreak(USCI_A0_BASE);
156 
157  //Wait till module is ready to transmit next data
158  while (!USCI_A_UART_getInterruptStatus(USCI_A0_BASE,
159  USCI_A_UART_TRANSMIT_INTERRUPT_FLAG)) ;
160 
161  //Transmit next data
162  USCI_A_UART_transmitData(USCI_A0_BASE,
163  transmitData++);
164  }
165 
166  break;
167  default: break;
168  }
169 }
170 
MPU_initThreeSegmentsParam param
__no_operation()
#define STATUS_FAIL
Definition: hw_memmap.h:23